package cn.tedu.hotelApi.dict.service.impl;

import cn.tedu.hotelApi.dict.mapper.DictMapper;
import cn.tedu.hotelApi.dict.pojo.dto.DictParam;
import cn.tedu.hotelApi.dict.pojo.dto.DictQuery;
import cn.tedu.hotelApi.dict.pojo.entity.Dict;
import cn.tedu.hotelApi.dict.pojo.vo.DictVO;
import cn.tedu.hotelApi.dict.service.DictService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class DictServiceImpl implements DictService {
    @Autowired
    private DictMapper dictMapper;
    @Override
    public List<DictVO> dictSelect(DictQuery dictQuery) {
        List<DictVO> dictVOS = dictMapper.selectDict(dictQuery);
        return dictVOS;
    }

    @Override
    public void dictSave(DictParam dictParam) {
        Dict dict = new Dict();
        BeanUtils.copyProperties(dictParam,dict);
        if (dict.getId() != null){
            dictMapper.updateDict(dict);
        }else {
            dict.setCreateTime(new Date());
            dictMapper.insertDict(dict);
        }
    }

    @Override
    public void dictDelect(Long id) {
        dictMapper.delectDict(id);
    }
}
